/**
 * THPS Dedicated Server
**/

#ifdef _THPS_
/**
 * Creates our CRC32 Table
**/
void CreateCRCTable()
{
    int i, j;
    unsigned long c;

    for( i = 0; i < 256; ++i )
    {
        for( c = i << 24, j = 8; j > 0; --j )
        {
            c = c & 0x80000000 ? (c << 1) ^ CRC32_POLY : (c << 1);
        }

        crc32_table[i] = c;
    }
}

/**
 * Generates CRC32 for a modified packet
**/
unsigned short GeneratePacketCRC( unsigned char *buffer, unsigned long bufferSize )
{
    unsigned long rc = 0xffffffff,
                  rc2,
                  i;

    for( i = 2; i < bufferSizeize; ++i )
        rc = crc32_table[(rc^buffer[i]) & 0xff] ^ ((rc>>8) & 0x00ffffff);

    rc2 = rc >> 0x10;
    rc  += rc2;

return (unsigned short)rc;
}

/**
 * Decodes a packet
**/
void DecodePacket(unsigned char *packet, unsigned long packetSize )
{
    unsigned long i;

    for( i = 2; i < packetSize; ++i )
        *(packet + i) ^= packet[0];
}
#endif
